from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QApplication, QPushButton, QSpacerItem, QSizePolicy, QCheckBox
from PyQt5.QtGui import QPalette, QColor
from qdarkstyle import load_stylesheet_pyqt5

class Set_theme(QWidget):
    IsSetTheme_signal = pyqtSignal()
    def __init__(self):
        super(Set_theme, self).__init__()
        self.setWindowTitle("设置主题")
        self.setWindowModality(Qt.WindowModal)
        self.resize(250, 100)
        self.all_layout = QVBoxLayout()
        self.up_layout = QHBoxLayout()
        self.first_Spacer = QSpacerItem(15, 10, QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.label1 = QCheckBox("黑色")
        self.label2 = QCheckBox("浅灰色")
        self.label3 = QCheckBox("白色")
        self.two_Spacer = QSpacerItem(5, 10, QSizePolicy.Fixed, QSizePolicy.Fixed)

        self.up_layout.addSpacerItem(self.first_Spacer)
        self.up_layout.addWidget(self.label1)
        self.up_layout.addWidget(self.label2)
        self.up_layout.addWidget(self.label3)
        self.all_layout.addLayout(self.up_layout)

        self.down_layout = QHBoxLayout()
        self.save_button = QPushButton("保存")
        self.save_button.setFixedWidth(60)
        self.save_button.setFixedHeight(30)
        self.down_layout.addSpacerItem(self.two_Spacer)
        self.down_layout.addWidget(self.save_button)
        self.all_layout.addLayout(self.down_layout)

        self.setLayout(self.all_layout)
        self.setup_signal()

    def setup_signal(self):
        self.save_button.clicked.connect(self.Function_save)
        self.label1.stateChanged.connect(self.check1)
        self.label2.stateChanged.connect(self.check2)
        self.label3.stateChanged.connect(self.check3)

    def check1(self, status):
        if status == Qt.Checked:
            print("点击")
            self.label2.setChecked(False)
            self.label3.setChecked(False)

    def check2(self, status):
        if status == Qt.Checked:
            self.label1.setChecked(False)
            self.label3.setChecked(False)

    def check3(self, status):
        if status == Qt.Checked:
            self.label1.setChecked(False)
            self.label2.setChecked(False)

    def Function_save(self):
        if self.label1.isChecked():
            palette = QPalette()
            palette.setColor(QPalette.Background, Qt.black)
            self.setPalette(palette)
            self.label1.setStyleSheet("""QCheckBox {background-color:black;}""")
            self.label2.setStyleSheet("""QCheckBox {background-color:black;}""")
            self.label3.setStyleSheet("""QCheckBox {background-color:black;}""")
            self.save_button.setStyleSheet("""QPushButton {background-color:black;}""")

        elif self.label2.isChecked():
            palette = QPalette()
            palette.setColor(QPalette.Background, QColor(49, 54, 59))
            self.setPalette(palette)
            self.label1.setStyleSheet("""QCheckBox {background-color:rgb(49, 54, 59);}""")
            self.label2.setStyleSheet("""QCheckBox {background-color:rgb(49, 54, 59);}""")
            self.label3.setStyleSheet("""QCheckBox {background-color:rgb(49, 54, 59);}""")
            self.save_button.setStyleSheet("""QPushButton {background-color:rgb(49, 54, 59);}""")
        elif self.label3.isChecked():
            palette = QPalette()
            palette.setColor(QPalette.Background, Qt.white)
            self.setPalette(palette)
            self.label1.setStyleSheet("""QCheckBox {background-color:rgb(255, 255, 255);}""")
            self.label2.setStyleSheet("""QCheckBox {background-color:rgb(255, 255, 255);}""")
            self.label3.setStyleSheet("""QCheckBox {background-color:rgb(255, 255, 255);}""")
            self.save_button.setStyleSheet("""QPushButton {background-color:rgb(255, 255, 255);}""")

        self.IsSetTheme_signal.emit()


if __name__ == '__main__':
    from sys import argv, exit
    app = QApplication(argv)
    app.setStyleSheet(load_stylesheet_pyqt5())
    demo = Set_theme()
    demo.show()
    exit(app.exec_())

